import request from '@/utils/axios-req'
const SERVERURL = import.meta.env.VITE_APP_BASE_MIAN_URL

// const SERVERURL = 'http://localhost:8000'
// ### 管理员创建用户
export const registerUser = ({ username, password, email, phone, name }) => {
  return request({
    url: `${SERVERURL}/admin/users/create`,
    reqLoading: false,
    method: 'post',
    data: {
      username,
      password,
      email,
      phone,
      name,
      role: 2
    }
  })
}

// ### 管理员获取用户列表
export const getUserList = ({ page, size }) => {
  return request({
    url: `${SERVERURL}/admin/users/findall?skip=${page}&limit=${size}`,
    reqLoading: false,
    method: 'get'
  })
}

// ### 管理员获取用户详情
export const getUserDetail = (userid) => {
  return request({
    url: `${SERVERURL}/admin/users/findone/${userid}`,
    reqLoading: false,
    method: 'get'
  })
}

// ### 管理员修改用户信息
export const alterUserDetail = (formdata) => {
  const { id, username, password, name, phone, email } = formdata
  return request({
    url: `${SERVERURL}/admin/users/update/${id}`,
    reqLoading: false,
    method: 'post',
    data: {
      username,
      password,
      name,
      phone,
      email
    }
  })
}

// ### 管理员删除用户信息
export const deleteUser = (userid) => {
  return request({
    url: `${SERVERURL}/admin/users/delete/${userid}`,
    reqLoading: false,
    method: 'delete'
  })
}


// ### 管理员创建用户
// POST http://localhost:8000/admin/users/create
// Content-Type: application/json
// Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzdXBlcm1hbjAxIiwiZXhwIjoxNzE1MDAzMzgxfQ.nJoWIZmrnvqTMWscpsjDi050zJAj1i6bkmFP3owzBAs

// {
//   "username": "jay",
// 	"password": "jaypassword",
// 	"email": "2341334123@qq.com",
// 	"phone": "+8618700002214",
// 	"role": 2,
// 	"name": "Jay"
// }

// ### 管理员获取用户列表
// GET http://localhost:8000/admin/users/findall?skip=0&limit=10
// Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzdXBlcm1hbjAxIiwiZXhwIjoxNzE1MDA4MzA4fQ.xlVYoaN1Y3z5xpyZ66AW6ZH-Qo_3mKKviBGHrxmIthM

// ### 管理员获取用户列表[验证普通用户是否无权限]
// GET http://localhost:8000/admin/users/findall?skip=0&limit=10
// Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqYXkiLCJleHAiOjE3MTUwMTc5MTR9.7WKFEUlLDc6emjt8QR0erpUoSP4N6h_etx3K8tTU2lI

// ### 管理员获取用户详情[根据用户ID]
// GET http://localhost:8000/admin/users/findone/1
// Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzdXBlcm1hbjAxIiwiZXhwIjoxNzE1MDA4MzA4fQ.xlVYoaN1Y3z5xpyZ66AW6ZH-Qo_3mKKviBGHrxmIthM

// ### 管理员更新用户信息[根据用户ID]
// PUT http://localhost:8000/admin/users/update/5
// Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzdXBlcm1hbjAxIiwiZXhwIjoxNzE1MDA4MzA4fQ.xlVYoaN1Y3z5xpyZ66AW6ZH-Qo_3mKKviBGHrxmIthM
// Content-Type: application/json

// {
//   "username": "superman032",
// 	"password": "new22113332323_password",
// 	"phone": "+8619200001113",
// 	"email": "12411223@qq.com"
// }

// ### 管理员删除用户[根据用户ID]
// DELETE http://localhost:8000/admin/users/delete/3
// Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzdXBlcm1hbjAxIiwiZXhwIjoxNzE1MDA4MzA4fQ.xlVYoaN1Y3z5xpyZ66AW6ZH-Qo_3mKKviBGHrxmIthM

